
/**
 * **********************************************************************
 * Thread.java
 * Universidad del Valle de Guatemala
 * Algoritmos y Estructura de Datos
 * @autor Martín Guzmán, Karen Tojín, Jeffry Turcios, David Coronado
 * Fecha: 30 de noviembre de 2009
 * **********************************************************************
 */
/**
 * Descripción: clase que maneja los threads
 */
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Thread_2 extends Thread {

    /**
     * Método constructor para la clase thread
     */
    public Thread_2() {
        super();
    }

    /**
     * Método que corre un thread
     */
    public void run() {

        if (Server.cola.empty() == true) {
        } else {

            while (Server.cola.empty() == false) {
                Request request_temp = Server.cola.pop();
                Server.Realizar_Request(request_temp);
            }

            //*************************************************************
            //para responderle al cliente
            //*************************************************************
            ObjectOutputStream slout = null;
            try {
                slout = new ObjectOutputStream(Server.s1.getOutputStream());
            } catch (IOException ex) {
                Logger.getLogger(Thread_2.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                Server.Guardar_log();
            } catch (IOException ex) {
                Logger.getLogger(Thread_2.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                //*************************************************************
                //Respuesta del servidor al cliente
                //*************************************************************
                //System.out.println(respuesta);
                slout.writeObject(Server.respuesta);
            } catch (IOException ex) {
                Logger.getLogger(Thread_2.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                Server.Guardar_hashes();
            } catch (IOException ex) {
                Logger.getLogger(Thread_2.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                Server.s1.close();
            } catch (IOException ex) {
                Logger.getLogger(Thread_2.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

